using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.DataTier.Source;

namespace OR.Lazarus.Library.DataTier.Source.Lazarus
{
	/// <summary>
	/// Defines any filters to be applied to the method processing.
	/// </summary>
   public class FilterDetail : EntityBase
   {
		protected System.String mName;
		protected string mField;
		protected string mParam;
		protected string mValue;
		protected string mDescription;

		public FilterDetail()
		{
	
		}
	
		/// <summary>
		/// Specifies a unique name for the entity.
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// Specifies the field that the filter will be applied to.
		/// </summary>
		public string Field
		{
			get
			{
				return ( mField );
			}
			set
			{
				mField = value;
			}
		}

		/// <summary>
		/// Specifies the name of the parameter for the filter.
		/// </summary>
		public string Param
		{
			get
			{
				return ( mParam );
			}
			set
			{
				mParam = value;
			}
		}

		/// <summary>
		/// Specifies a value to apply to the filter.  This will act as a default to the parameter.
		/// </summary>
		public string Value
		{
			get
			{
				return ( mValue );
			}
			set
			{
				mValue = value;
			}
		}

		/// <summary>
		/// Provides a long-text description for the entity.
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mField = DataUtility.GetString( pSource, "field" );
			mParam = DataUtility.GetString( pSource, "param" );
			mValue = DataUtility.GetString( pSource, "value" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lz:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lz", "method-filter", "http://schemas.icitadel.com/Lazarus/Source.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mField ) )
			{
				vNewElement.SetAttribute( "field", mField );
			}
					
			if ( !String.IsNullOrEmpty( mParam ) )
			{
				vNewElement.SetAttribute( "param", mParam );
			}
					
			if ( !String.IsNullOrEmpty( mValue ) )
			{
				vNewElement.SetAttribute( "value", mValue );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lz", "description", "http://schemas.icitadel.com/Lazarus/Source.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.FilterDetail v_oReturn = new Derived.FilterDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Field = mField;
			v_oReturn.Param = mParam;
			v_oReturn.Value = mValue;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.FilterDetail CloneTyped()
		{
			return ( ( Derived.FilterDetail )this.Clone() );
		}
   }
}
   